<?php
class SubjectUriController extends BaseController
{
    private $id;
    public function __construct($uri)
    {
        parent::__construct($uri);
        $tmp = explode('/', $this->uri);
        $this->id = $tmp[2];
    }

    public function add()
    {
        $this->checkLogin();
        $m = new MovieModel();
        $r = array();
        $r['movie'] = $m->get($this->id);
        $r['providers'] = $m->getProviders();
        $this->output['tpl'] = 'subject/uri/add';
        $this->output['data'] = $r;
        return $this->output;
    }

    public function addSubmit()
    {
        $user = $this->checkLogin();
        $data = $this->input;
        $data['movie_id'] = $this->id;
        $data['user_id'] = $user['user_id'];
        switch ($this->input['download']) {
            case 'free_genuine_download' :
                $data['is_free'] = 1;
                $data['is_genuine'] = 1;
                $data['is_direct_download'] = 0;
                break;
            case 'chargeable_genuine_download' :
                $data['is_free'] = 0;
                $data['is_genuine'] = 1;
                break;
            case 'free_direct_download' :
                $data['is_free'] = 1;
                $data['is_direct_download'] = 1;
                //if(ProviderDb::$protocol) {
                if(!empty($this->input['torrent_filename'])) {
                    $data['torrent_id'] = substr($data['torrent_filename'], 0, 32);
                }
                break;
        }
        $m = new MovieModel();
        $r = $m->addUri($data);
        $this->output['tpl'] = 'subject/uri/add_submit';
        $this->output['data'] = $data;
        return $this->output;
    }
}
?>
